<html>
<head><meta charset="utf-8"><title>impl Trait+Sized vs. impl Trait · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/impl.20Trait.2BSized.20vs.2E.20impl.20Trait.html">impl Trait+Sized vs. impl Trait</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="220125646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/impl%20Trait%2BSized%20vs.%20impl%20Trait/near/220125646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/impl.20Trait.2BSized.20vs.2E.20impl.20Trait.html#220125646">(Dec 16 2020 at 14:59)</a>:</h4>
<p>I am currently writing a recommendation for a scheme of mangling rust types as Itanium names. I was wondering if there was a notable distinction between <code>impl Trait</code>and <code>impl Trait+Sized</code>, and thus if they should mangle differently. Under the current schme (for example using <code>Copy</code> for <code>Trait</code>),  the <code>impl Copy</code> would mangle as <code>u4implIN4core6marker4CopyE</code>, and <code>impl Copy+Sized</code> would be <code>u4implIN4core6marker4CopyNS0_5SizedE</code> (noting that <code>S0_</code> stands in the substitution dictionary for <code>core::marker</code>) (this needs to be fixed for return type position, since it is a unique type in each position). </p>
<p>Would this be a valid distinction to make, or should both use the same mangling (in which case, preferring the one without the explicit <code>Sized</code>). Or in particular, does rust consider these types different, and, if so, can this difference be observed? (If the answer to both is no, or the first is yes, the more verbose option would be used, so that the source declaration can be easily recovered from the mangled name)</p>



<a name="220223235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/impl%20Trait%2BSized%20vs.%20impl%20Trait/near/220223235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/impl.20Trait.2BSized.20vs.2E.20impl.20Trait.html#220223235">(Dec 17 2020 at 09:48)</a>:</h4>
<p>FWIW, the official Rust name mangling is described at <a href="https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html">https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html</a>. It even mentions Itanium. I am not sure if that supports types though.</p>



<a name="220237281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/impl%20Trait%2BSized%20vs.%20impl%20Trait/near/220237281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/impl.20Trait.2BSized.20vs.2E.20impl.20Trait.html#220237281">(Dec 17 2020 at 12:33)</a>:</h4>
<p>What I can see from that is that <code>impl Trait+w/e</code> (at least in the return position), is the deduced return type of the function? Is there anything for it at any other position (particularily, the parameter position)? Is it just encoded as an extra generic argument?</p>
<p>That actually makes sense. So then I guess it would be completely indistinguishable, then. I can certainly encode them separately (so that, when demangled, you can note whether <code>+Sized</code> was included). <br>
Although, it is interesting that it does not mangle to a local type, or some other form of unnamed type in this position. </p>
<p>I am aware of the rust name mangling. However, as it stands, rust still has an unstable ABI. For lccc (for those unaware, this is a work-in-progress implementation of rust among others), which also compiles C++, itanium name mangling is more important, because that is a fully specified ABI for C++ implementations. It may be reasonable to provide an option to select name mangling scheme for a symbol (and provide rust mangling as one), though this would be more important as rust gets closer to having some form of stable ABI.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>